package es.urjc.ldm.componentes;

import es.urjc.ldm.carrodecompra.*;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.NumberPicker;

public class NumberPickerDialog extends AlertDialog implements OnClickListener {
    private OnNumberSetListener mListener;
    private NumberPicker mNumberPicker;
    private int mInitialValue;
    private int currentlyValue;

	/** Constructor de la clase ListProduct, inicializa el contador de articulos y su precio
	 *
	 * @author manuelgblanco
	 * @version 1.0z 1 Abril, 2013.
	 * @param
	 * @return 
	 */
    public NumberPickerDialog(Context context, int theme, int initialValue) {

    	super(context, theme);
         
        mInitialValue = initialValue;

        setButton(BUTTON_POSITIVE, context.getText(R.string.number_picker_dialog_accept), this);
        setButton(BUTTON_NEGATIVE, context.getText(R.string.number_picker_dialog_cancel), (OnClickListener) null);
        setTitle(context.getText(R.string.number_picker_dialog_title));

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.number_picker_dialogo, null);
        setView(view);

        mNumberPicker = (NumberPicker) view.findViewById(R.id.numberPicker);
        mNumberPicker.setMaxValue(200);
        mNumberPicker.setMinValue(0);
        mNumberPicker.setWrapSelectorWheel(true);
       
        mNumberPicker.setValue(mInitialValue);

    }

	/** Constructor de la clase ListProduct, inicializa el contador de articulos y su precio
	 *
	 * @author manuelgblanco
	 * @version 1.0z 1 Abril, 2013.
	 * @param
	 * @return 
	 */
    public void setOnNumberSetListener(OnNumberSetListener listener) {
        mListener = listener;
    }

    @Override
	/** Constructor de la clase ListProduct, inicializa el contador de articulos y su precio
	 *
	 * @author manuelgblanco
	 * @version 1.0z 1 Abril, 2013.
	 * @param
	 * @return 
	 */
    public void onClick(DialogInterface dialog, int which) {
    	currentlyValue =  mNumberPicker.getValue();
    	
    }

	/** Constructor de la clase ListProduct, inicializa el contador de articulos y su precio
	 *
	 * @author manuelgblanco
	 * @version 1.0z 1 Abril, 2013.
	 * @param
	 * @return 
	 */
    public int getValue(){
    	return currentlyValue;
    }
    
	/** Constructor de la clase ListProduct, inicializa el contador de articulos y su precio
	 *
	 * @author manuelgblanco
	 * @version 1.0z 1 Abril, 2013.
	 * @param
	 * @return 
	 */
    public interface OnNumberSetListener {
        public void onNumberSet(int selectedNumber);
    }
}
